package com.centaline.androidsalesblog.widgets;

import android.content.Context;
import android.support.percent.PercentRelativeLayout;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.model.databaseobject.StaffDo;

import java.util.ArrayList;

/**
 * 详情底部工具栏
 * Created by guilin on 16/3/4.
 */
public class DetailToolsView extends PercentRelativeLayout {

    private AppCompatTextView atv_yue_kan,atv_count;
    private Button btn_add_yue_kan, btn_consult;

    private YueKanOnClick yueKanOnClick;

    private OnClickListener mOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v == atv_yue_kan) {
                if (yueKanOnClick != null)
                    yueKanOnClick.gotoYueKanBill();
            } else if (v == btn_add_yue_kan) {
                if (yueKanOnClick != null)
                    yueKanOnClick.addYueKan();
            } else if (v == btn_consult) {
                if (yueKanOnClick != null)
                    yueKanOnClick.consult();
            }
        }
    };

    public DetailToolsView(Context context) {
        this(context, null);
    }

    public DetailToolsView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DetailToolsView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        inflate(context, R.layout.layout_detail_tools, this);
        atv_yue_kan = (AppCompatTextView) findViewById(R.id.atv_yue_kan);
        atv_yue_kan.setOnClickListener(mOnClickListener);
        btn_add_yue_kan = (Button) findViewById(R.id.btn_add_yue_kan);
        btn_add_yue_kan.setOnClickListener(mOnClickListener);
        btn_consult = (Button) findViewById(R.id.btn_consult);
        atv_count = (AppCompatTextView) findViewById(R.id.atv_count);
        btn_consult.setOnClickListener(mOnClickListener);

    }

    public void setStaffs(ArrayList<StaffDo> staffs) {
        btn_consult.setEnabled(staffs != null && staffs.size() > 0);
    }

    /**
     * 约看数量
     */
    public void setReserveCount(int count) {
        atv_yue_kan.setText("约看单");
        if (count > 0) {
            atv_count.setText(String.valueOf(count));
            atv_count.setVisibility(VISIBLE);
        } else {
            atv_count.setVisibility(GONE);
        }
    }

    /**
     * 添加监听
     */
    public void setYueKanOnClick(YueKanOnClick yueKanOnClick) {
        this.yueKanOnClick = yueKanOnClick;
    }

    public interface YueKanOnClick {

        /**
         * 约看单
         */
        void gotoYueKanBill();

        /**
         * 添加看单
         */
        void addYueKan();

        /**
         * 咨询
         */
        void consult();
    }
}
